The present invention relates generally to computer memory systems, and more particularly, to the management of memory allocation.
Computer operating systems dynamically allocate memory in a computer system while executing programs. Computer memory is allocated to the executing program for use by functions within the program. When the functions are completed, the memory allocated for the functions are typically de-allocated. Frequent allocation and de-allocation of a large number of fixed size data structures may result in memory fragmentation, which can lead to performance degradation or even malfunctions.
Dynamic memory allocation is a technique in which programs determine as they are running where to store information. Dynamic allocation is used when the number of memory blocks needed, or the length of time needed, depends on the data being processed. For example, a block may be needed to store a line read from an input file. Since there is no limit to how long a line can be, the storage must be allocated dynamically, and made dynamically larger as more of the line is read. Also, a block may be needed for each record or each definition in the input data. Since it is not known in advance how many records there will be, a new block must be allocated for each record as it is read. In order to improve efficiency, when an amount of memory is requested, a higher amount of memory defined as a xe2x80x9cchunkxe2x80x9d may be allocated.
A chunk manager is often used to manage chunk memory allocation from an operating system to an application. The chunk manager allocates large blocks of memory chunks and then subdivides the blocks into smaller fixed size blocks (chunk elements) that can be used for fixed size data structures. FIG. 1 illustrates a memory chunk C subdivided into a plurality of chunk elements E, with allocated blocks indicated with shading. An application may request 50 elements having 100 bytes each from a chunk manager, for example. The chunk manager will then request a 5,000 byte block containing a plurality of smaller size block elements and allocate this memory to the application. Individual block elements within the large block may be used by the application and then returned at various times while the application is running. As memory blocks are allocated and deallocated during system operation, the memory fragments and free blocks are located between used ones (see FIG. 1). When the memory is fragmented, there may be a large amount of total free space, but each block may be too small for use by applications to store data. For example, an application may request a chunk of memory which is less than the total free memory, but not available as one chunk due to fragmentation of the system memory. As data structures in a system differ in the size and dynamicity of allocation and de-allocation, memory chunks of different sizes have to be used to conserve memory. Since the sizes of memory chunks differ, frequent allocation and de-allocation of elements often leads to memory fragmentation which may result in system performance degradation and malfunctions.
There is, therefore, a need for a chunk manager that allows for flexibility in the size of chunks allocated to increase the availability of memory blocks and reduce errors encountered due to memory fragmentation.
A memory allocation system and method are disclosed. A method of the present invention is for allocating computer memory for a function in a computer program by a chunk manager operable to interface with an operating system of a computer and the program. The method generally includes receiving a request for a block of memory for a function in the computer program. The request is modified such that the size of the requested block corresponds to a standard block size selected from a list of standard block sizes. The method further includes locating a first available block of memory having a size within a predefined range around the requested block size.
A system for allocating computer memory generally comprises a chunk manager operable to receive a request from a computer program for a block of memory and modify the request such that the size of the requested memory block corresponds to a standard block size. The chunk manager is further operable to locate a first available block of memory having a size within a predefined range around the requested block size.
In another aspect of the invention, a computer system generally includes a central processing unit coupled to a memory unit. The memory comprises a memory array for storing data comprising data bits. The memory stores the data within the array in memory chunks, each memory chunk being divided into a plurality of memory elements having predefined number of data bits. The system further includes a chunk manager operable to allocate variable sized memory chunks to a computer application. The chunks are allocated based on a predefined allowable range around a chunk size requested by a program.
A computer program product for allocating computer memory generally comprises computer code that allows the chunk manager to receive a request for a block of memory for a function in a computer program. The product further includes computer code that modifies the request such that the size of the requested block corresponds to a standard block size selected from a list of standard block sizes, computer code that locates a first available block of memory having a size within a predefined range around the requested block size, and a computer readable medium that stores the computer codes.
The above is a brief description of some deficiencies in the prior art and advantages of the present invention. Other features, advantages, and embodiments of the invention will be apparent to those skilled in the art from the following description, drawings, and claims.